package com.ruoyi.hqfinance.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.hqfinance.domain.HqBillCollect;
import com.ruoyi.hqfinance.domain.HqBillDataShow;
import com.ruoyi.hqfinance.domain.HqBillNearlySevenDay;
import com.ruoyi.hqfinance.domain.vo.HqBillCollectVo;
import com.ruoyi.hqfinance.domain.vo.HqBillDataShowVo;
import com.ruoyi.hqfinance.service.HqBillCollectService;
import com.ruoyi.logistic.domain.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/hq/billCollect")
@Api(tags = "总部财务-网点账单")
public class HqBillCollectController {
    @Autowired
    private HqBillCollectService hqBillCollectService;

    @ApiOperation("数据汇总")
    @PostMapping("/collect")
    public R collect(@RequestBody HqBillCollectVo vo){
        if (vo != null){
            String startTime = vo.getStartTime().replace("-", "");
            String endTime = vo.getEndTime().replace("-", "");
            vo.setStartTime(startTime);
            vo.setEndTime(endTime);
        }else {
            return R.ok("请传入必要的时间参数");
        }
        List<HqBillCollect> billCollectList = hqBillCollectService.collect(vo);
        if (billCollectList == null || billCollectList.size() == 0){
            return R.ok("暂无数据");
        }else {
            return R.ok(PageInfo.info(billCollectList));
        }
    }



    @ApiOperation("各费用项收支")
    @PostMapping("/billDataShow")
    public R billDataShow(@RequestBody HqBillDataShowVo vo){
        List<HqBillDataShow> dataShowList = hqBillCollectService.billDataShow(vo);
        if (dataShowList == null || dataShowList.size() == 0){
            return R.ok("暂无数据");
        }else {
            String[] s = {"奖惩","面单","派费","中转","总部市场","其他"};
            for (int i = 0; i < 6; i++) {
                HqBillDataShow hqBillDataShow = dataShowList.get(i);
                hqBillDataShow.setTypeName(s[i]);
            }
            return R.ok(dataShowList);
        }
    }

    @ApiOperation("近七天趋势")
    @GetMapping("/nearlySevenDay")
    public R nearlySevenDay(@RequestParam("costBigKind") String costBigKind){
        List<HqBillNearlySevenDay> nearlySevenDays = hqBillCollectService.nearlySevenDay(costBigKind);
        if (nearlySevenDays == null || nearlySevenDays.size() == 0){
            return R.ok("暂无数据");
        }else {
            return R.ok(nearlySevenDays);
        }
    }

    @ApiOperation("卡片和近七天趋势图")
    @PostMapping("/cardAndSeven")
    public R cardAndSeven(@RequestBody HqBillDataShowVo vo){
        return R.ok(hqBillCollectService.data(vo));
    }
}
